echo '安装MySQL软件包'
# 删除原来的mysql
yum remove mysql
# 获取mysql yum源
wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 获取MySQL软件包
rpm -ivh mysql57-community-release-el7-8.noarch.rpm

# 配置Mysql公钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

# yum包管理器安装MySQL服务
yum -y install mysql-server

echo '修改配置文件'
sudo tee /etc/my.cnf <<-'EOF'

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
 
[mysql]
default-character-set=utf8
 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-storage-engine=INNODB
character_set_server=utf8
 
symbolic-links=0
 
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

EOF

echo '配置防火墙端口'
# 查看防火墙状态
systemctl status firewalld
# 配置防火墙规则
firewall-cmd --zone=public --add-port=3306/tcp --permanent;
# 重新载入防火墙规则
firewall-cmd --reload
# 查看MySQL版本
mysql -V

# 启动服务
systemctl start mysqld
# 查看状态
systemctl status mysqld
# 设置开机自动启动
systemctl enable mysqld

ifconfig


